package com.example.demo;

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Description 展示Lock的方法
 * @Author
 * @Date 2019/7/23 19:07
 **/
public class LockExample15 {
    public static void main(String[] args) throws Exception{
        //服务器端通过服务器创建channel
        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
        //服务器端绑定端口
        serverSocketChannel.bind(new InetSocketAddress(8000));
        //服务器端监听客户端连接,建立socketChannel连接
        SocketChannel socketChannel = serverSocketChannel.accept();
        //客户端连接远程主机及端口
        SocketChannel open = SocketChannel.open(new InetSocketAddress("127.0.0.1", 8000));

        //Buffer类
        ByteBuffer byteBuffer = ByteBuffer.allocate(10);


        Selector selector = Selector.open();

        SelectionKey selectionKey = serverSocketChannel.register(selector, SelectionKey.OP_READ);

        int selectNum = selector.select();

        Set<SelectionKey> selectionKeys = selector.selectedKeys();
    }
}

